﻿@using TP_02.Models
@model IEnumerable<TP_02.Models.Game>

@{
    ViewBag.Title = "Index";
}
<p style="margin-top: 20px;">
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.GameRating)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.CategoryId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Developer)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @{
                var gameRating = item.GameRating;
            }
            @gameRating
        </td>
        <td>
            @{
                var gc = GameCategory.FindOne(item.CategoryId);
            }
            @if (gc == null)
            {
                <p>No Category </p>
            }
            else
            {
                @gc.Name
            }
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Developer)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })
        </td>
    </tr>
}

</table>
